#!/usr/bin/env python2.6
#
#  ssp-serial.py
#  
#
#  Created by Philip Asare on 10/18/10.
#  Copyright (c) 2010 __MyCompanyName__. All rights reserved.
#

import serial

def parse(data_str):
	data_str = data_str.split(':')
	nodenum = data_str[0]
	neighbors = data_str[1].split('/')
	for i in range(len(neighbors)):
		neighbors[i] = neighbors[i].split(',')
	sensors = data_str[2].split(',')
	node = [nodenum, neighbors, sensors]
	return node
	
# def configChange(yORn = no, rate, sense):
# 	ser.write(yORn)
# 	ser.write(rate)
# 	ser.write(sense)

start = "start\r\n"
end = "end\r\n"

yes = "\x01"
no = "\x00"

ser = serial.Serial('/dev/ttyUSB0', 115200, timeout=None)
data = []
while(1):
	data_str = ser.readline()
	if (data_str == start):
		data_str = ser.readline()
		while(data_str != end):
			data = parse(data_str)
			data_str = ser.readline()
			print data
